import {
  createNewCompany,
  delCompanyInfo,
  listAllAnhuiRegions, listAllByCompanyName,
  listAllCompanyInfos,
  queryBusinessCodes,
  updateCompanyInfo,
} from '@/services/companyinfoApi';

export default {
  namespace: 'companyinfo',

  state: {
    data: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    /**
     * 获取安徽省下的所有行政区划
     * @param _
     * @param call
     * @param put
     * @returns {Generator<*, void, *>}
     */
    *listAllAnhuiRegions({ payload }, { call, put }) {
      const response = yield call(listAllAnhuiRegions);
      return response;
    },

    /**
     * 模糊查询企业信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllByCompanyName({ payload }, { call, put }) {
      const response = yield call(listAllByCompanyName,payload);
      return response;
    },

    /**
     * 获取行业代码
     * @param _
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *queryBusinessCodes({ payload }, { call, put }) {
      const response = yield call(queryBusinessCodes, payload);
      return response;
    },

    /**
     * 分页获取企业列表数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllCompanyInfos({ payload }, { call, put }) {
      const response = yield call(listAllCompanyInfos, payload);
      yield put({
        type: 'cb4listAllCompanyInfos',
        payload: response,
      });
    },

    /**
     * 新增企业信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *createNewCompany({ payload }, { call, put }) {
      const response = yield call(createNewCompany, payload);
      return response;
    },

    /**
     * 更新企业信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *updateCompanyInfo({ payload }, { call, put }) {
      const response = yield call(updateCompanyInfo, payload);
      return response;
    },

    /**
     * 删除企业信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *delCompanyInfo({ payload }, { call, put }) {
      const response = yield call(delCompanyInfo, payload);
      return response;
    },
  },

  reducers: {
    cb4listAllCompanyInfos(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
